define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'sessions/index' + location.search,
                    add_url: 'sessions/add',
                    // edit_url: 'sessions/edit',
                    // del_url: 'sessions/del',
                    multi_url: 'sessions/multi',
                    import_url: 'sessions/import',
                    table: 'good_order_sessions',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'occupants_id', title: __('Occupants_id')},
                        {field: 'nickname', title: '昵称'},
                        {field: 'room_number', title:'房间号'},
                        {field: 'light_code', title:'灯码'},
                        {field: 'type', title:'类型', searchList: {"0":'用户点单',"1":'代客点单'}, formatter: Table.api.formatter.label},
                        {field: 'goodmoney', title:'总金额'},

                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'riderAssign',
                                    text: '详情',
                                    title: '详情',
                                    classname: 'btn btn-xs btn-info btn-click',
                                    icon: 'fa fa-flag',

                                    click: function (e, row) {
                                        console.log('riderAssign', e, row);
                                        Controller.api.showRiderDialog(row.id);
                                    }
                                },
                            ]
                        }

                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },

            showRiderDialog: function (id) {
                Fast.api.open('Goodorder/index?order_session_id='+id, '商品列表', {

                });
            },
        }
    };
    return Controller;
});